package com.ligang.controller;

import com.ligang.VideoService;
import com.ligang.domain.Video;
import com.ligang.domain.VideoOrder;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

import java.util.Date;

/**
 * @Author: StoneIsLand
 * @Date: 2021/12/15 22:18
 */
@RestController
@RequestMapping("api/v1/video_order")
public class OrderController {

    @Autowired
    private RestTemplate restTemplate;

    @Autowired
    private VideoService videoService;
    @PostMapping("/save")
    public Object save(int videoId){
//        Video video = restTemplate.getForObject("http://xdclass-video-service/api/v1/video/findById?id="+videoId, Video.class);
        Video video = videoService.findById(videoId);
        VideoOrder videoOrder=new VideoOrder();
        assert video != null;
        videoOrder.setVideoId(video.getId());
        videoOrder.setVideoTitle(video.getTitle());
        videoOrder.setCreateTime(new Date());
        videoOrder.setServerInfo(video.getServerInfo());
        return videoOrder;
    }

    @PostMapping("/saveVideo")
    public Object save(@RequestBody Video video){
        return videoService.save(video);
    }




}
